<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    //接口地址: https://api.apiopen.top/getJoke

    //包起来
    const p = new Promise((resolve,reject)=>{
        const xhr = new XMLHttpRequest();
        xhr.open('GET','https://api.apiopen.top/getJoke')
        xhr.send(null)
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4){
                if (xhr.status >=200 && xhr.status < 300){
                    resolve(xhr.response)
                }else {
                    reject(xhr.status)
                }
            }
        }
    })

    //成功和失败的回调
    p.then(function (value) {
        //在这做数据处理
        console.log('##'+ value)
    },function (reason) {
        console.log('$' + reason)
    })
</script>
</body>
</html>